﻿@{
    ViewBag.Title = "部门管理";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    var keyValue = request('keyValue');
    var organizeId = request('organizeId');
    var departmentId = request('departmentId');
    var parentId = request('parentId');
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //上级部门
        $("#F_OrganizeTree").ComboBoxTree({
            url: "../../BaseManage/Department/GetOrganizeTreeJson",
            description: "==请选择==",
            height: "250px",
            click: function (item) {
                if (item.Sort == 'Organize') {
                    organizeId = item.id;
                    parentId = 0;
                } else {
                    parentId = item.id;
                }
            }
        });
        //负责人
        $("#F_ManagerId").ComboBoxTree({
            url: "../../BaseManage/User/GetTreeJson",
            description: "==请选择==",
            height: "220px",
            allowSearch: true
        });
        //部门性质
        $("#F_Nature").ComboBox({
            url: "../../SystemManage/DataItemDetail/GetDataItemListJson",
            param: { EnCode: "DepartmentNature" },
            id: "F_ItemValue",
            text: "F_ItemName",
            description: "==请选择==",
            height: "200px"
        });
        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../BaseManage/Department/GetFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                    if (data.ParentId == 0) {
                        $("#F_OrganizeTree").ComboBoxTreeSetValue(data.F_OrganizeId);
                    } else {
                        $("#F_OrganizeTree").ComboBoxTreeSetValue(data.F_ParentId);
                    }
                    parentId = data.F_ParentId;
                    organizeId = data.F_OrganizeId;
                }
            });
        } else {
            $("#F_OrganizeTree").ComboBoxTreeSetValue(departmentId);
        }
    }
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["F_OrganizeId"] = organizeId;
        postData["F_ParentId"] = parentId;
        postData["F_Manager"] = $("#F_ManagerId").attr('data-text');
        $.SaveForm({
            url: "../../BaseManage/Department/SaveForm?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
</script>
<div style="margin-left: 10px; margin-top: 20px; margin-right: 30px;">
    <table class="form">
        <tr>
            <th class="formTitle">上级部门<font face="宋体">*</font></th>
            <td class="formValue">
                <div id="F_OrganizeTree" type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
            </td>
            <th class="formTitle">负责人</th>
            <td class="formValue">
                <div id="F_ManagerId" type="selectTree" class="ui-select"></div>
            </td>
        </tr>
        <tr>
            <th class="formTitle">部门名称<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="F_FullName" type="text" onblur="$.ExistField(this.id,'../../BaseManage/Department/ExistEnCode')" class="form-control" placeholder="请输入名称" isvalid="yes" checkexpession="NotNull" />
            </td>
            <th class="formTitle">部门编号<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="F_EnCode" type="text" onblur="$.ExistField(this.id,'../../BaseManage/Department/ExistFullName')" class="form-control" placeholder="请输入编号" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">部门简称</th>
            <td class="formValue">
                <input id="F_ShortName" type="text" class="form-control" />
            </td>
            <th class="formTitle">部门性质</th>
            <td class="formValue">
                <div id="F_Nature" type="select" class="ui-select"></div>
            </td>
        </tr>
        <tr>
            <th class="formTitle">电话号</th>
            <td class="formValue">
                <input id="F_OuterPhone" type="text" class="form-control" />
            </td>
            <th class="formTitle">分机号</th>
            <td class="formValue">
                <input id="F_InnerPhone" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">邮箱</th>
            <td class="formValue">
                <input id="F_Email" type="text" class="form-control" />
            </td>
            <th class="formTitle">传真</th>
            <td class="formValue">
                <input id="F_Fax" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;">备注
            </th>
            <td class="formValue" colspan="3">
                <textarea id="F_Description" class="form-control" style="height: 70px;"></textarea>
            </td>
        </tr>
    </table>
</div>
